<?php

/**
 * This is the model class for table "{{ticket_log}}".
 *
 * The followings are the available columns in table '{{ticket_log}}':
 * @property integer $ztl_id
 * @property integer $zm_id
 * @property integer $ztl_type
 * @property integer $zti_id
 * @property integer $ztl_num
 * @property integer $ztl_price
 * @property integer $inputtime
 */
class TicketLog extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return TicketLog the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{ticket_log}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('zm_id', 'numerical', 'integerOnly'=>true),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('ztl_id, zm_id, ztl_type, zti_id, ztl_num, ztl_price, inputtime', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'ticket'=> array(self::BELONGS_TO,'Ticket','zti_id')
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'ztl_id' => 'Ztl',
			'zm_id' => 'Zm',
			'ztl_type' => 'Ztl Type',
			'zti_id' => 'Zti',
			'ztl_num' => 'Ztl Num',
			'ztl_price' => 'Ztl Price',
			'inputtime' => 'Inputtime',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('ztl_id',$this->ztl_id);
		$criteria->compare('zm_id',$this->zm_id);
		$criteria->compare('ztl_type',$this->ztl_type);
		$criteria->compare('zti_id',$this->zti_id);
		$criteria->compare('ztl_num',$this->ztl_num);
		$criteria->compare('ztl_price',$this->ztl_price);
		$criteria->compare('inputtime',$this->inputtime);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}	
	
	/**
	 * 已使用优惠券列表
	 * @return CActiveDataProvider 
	 */
	public function listSearch()
	{
		$criteria=new CDbCriteria;

		$criteria->compare('t.zm_id',Yii::app()->user->userid);
		$criteria->compare('ztl_type',2);
		$criteria->with = 'ticket';
		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
	
// 	protected function beforeSave(){
// 		if (parent::beforeSave()){
// 			$this->inputtime=time();
// 			return true;
// 		}else{
// 			return false;
// 		}
// 	}
}